package com.juc.concurrency.jucExample.executorsThreadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * ScheduledExecutorService的4个方法
 * 1.schedule(Runnable command,long delay, TimeUnit unit)
 * 2.schedule(Callable<V> callable,long delay, TimeUnit unit)
 * 3.scheduleAtFixedRate(Runnable command,long initialDelay,long period,TimeUnit unit)
 * 4.scheduleWithFixedDelay(Runnable command, long initialDelay,long delay,TimeUnit unit)
 */
@Slf4j
public class NewScheduledThreadPoolExample2 {

    public static void main(String[] args) {

        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        executorService.schedule(new Runnable() {
            @Override
            public void run() {
                log.warn("schedule run");
            }
        }, 3, TimeUnit.SECONDS);

        executorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                log.warn("schedule run");
            }
        }, 1, 3, TimeUnit.SECONDS);
//        executorService.shutdown();

//        Timer timer = new Timer();
//        timer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                log.warn("timer run");
//            }
//        }, new Date(), 5 * 1000);
    }
}
